#pragma once

#include "TemplateParameter.h"

#include "ParameterableElement.h"
#include "TemplateSignature.h"

namespace uml {

TemplateParameter::TemplateParameter(const QString& umlType)
    : Element(umlType) {}

void TemplateParameter::fromJson(const QJsonObject& json, QStringList& errorList) {
    if (json.isEmpty()) {
        return;
    }

    Element::fromJson(json, errorList);
    default2_ = JsonSerializable::create<ParameterableElement>(json.value("default2"), errorList);

    ownedDefault_ = JsonSerializable::create<ParameterableElement>(json.value("ownedDefault"), errorList);

    ownedParameteredElement_ = JsonSerializable::create<ParameterableElement>(json.value("ownedParameteredElement"), errorList);

    parameteredElement_ = JsonSerializable::create<ParameterableElement>(json.value("parameteredElement"), errorList);

    signature_ = JsonSerializable::create<TemplateSignature>(json.value("signature"), errorList);

}

void TemplateParameter::toJson(QJsonObject& json) {
    Element::toJson(json);
    if (default2_) {
        QJsonObject default2_json;
        default2_->toJson(default2_json);
        json.insert("default2", default2_json);
    }
    if (ownedDefault_) {
        QJsonObject ownedDefault_json;
        ownedDefault_->toJson(ownedDefault_json);
        json.insert("ownedDefault", ownedDefault_json);
    }
    if (ownedParameteredElement_) {
        QJsonObject ownedParameteredElement_json;
        ownedParameteredElement_->toJson(ownedParameteredElement_json);
        json.insert("ownedParameteredElement", ownedParameteredElement_json);
    }
    if (parameteredElement_) {
        QJsonObject parameteredElement_json;
        parameteredElement_->toJson(parameteredElement_json);
        json.insert("parameteredElement", parameteredElement_json);
    }
    if (signature_) {
        QJsonObject signature_json;
        signature_->toJson(signature_json);
        json.insert("signature", signature_json);
    }
}

/// <summary>
/// default2 getter
/// The ParameterableElement that is the default for this formal TemplateParameter.
/// </summary>
shared_ptr<ParameterableElement> TemplateParameter::default2() const {
    return default2_;
}

/// <summary>
/// default2 setter
/// The ParameterableElement that is the default for this formal TemplateParameter.
/// </summary>
void TemplateParameter::setDefault2(shared_ptr<ParameterableElement> value) {
    default2_ = value;
}

/// <summary>
/// ownedDefault getter
/// The ParameterableElement that is owned by this TemplateParameter for the purpose
/// of providing a default.
/// </summary>
shared_ptr<ParameterableElement> TemplateParameter::ownedDefault() const {
    return ownedDefault_;
}

/// <summary>
/// ownedDefault setter
/// The ParameterableElement that is owned by this TemplateParameter for the purpose
/// of providing a default.
/// </summary>
void TemplateParameter::setOwnedDefault(shared_ptr<ParameterableElement> value) {
    ownedDefault_ = value;
}

/// <summary>
/// ownedParameteredElement getter
/// The ParameterableElement that is owned by this TemplateParameter for the purpose
/// of exposing it as the parameteredElement.
/// </summary>
shared_ptr<ParameterableElement> TemplateParameter::ownedParameteredElement() const {
    return ownedParameteredElement_;
}

/// <summary>
/// ownedParameteredElement setter
/// The ParameterableElement that is owned by this TemplateParameter for the purpose
/// of exposing it as the parameteredElement.
/// </summary>
void TemplateParameter::setOwnedParameteredElement(shared_ptr<ParameterableElement> value) {
    ownedParameteredElement_ = value;
}

/// <summary>
/// parameteredElement getter
/// The ParameterableElement exposed by this TemplateParameter.
/// </summary>
shared_ptr<ParameterableElement> TemplateParameter::parameteredElement() const {
    return parameteredElement_;
}

/// <summary>
/// parameteredElement setter
/// The ParameterableElement exposed by this TemplateParameter.
/// </summary>
void TemplateParameter::setParameteredElement(shared_ptr<ParameterableElement> value) {
    parameteredElement_ = value;
}

/// <summary>
/// signature getter
/// The TemplateSignature that owns this TemplateParameter.
/// </summary>
shared_ptr<TemplateSignature> TemplateParameter::signature() const {
    return signature_;
}

/// <summary>
/// signature setter
/// The TemplateSignature that owns this TemplateParameter.
/// </summary>
void TemplateParameter::setSignature(shared_ptr<TemplateSignature> value) {
    signature_ = value;
}

} // namespace uml
